R: How to Draw Circles in Plots (With Examples) |
您所在的位置:网站首页 › dataframe plot scatter › R: How to Draw Circles in Plots (With Examples) |
You can use the following methods to draw a circle in a plot in R: Method 1: Draw Circle Using Base R library(plotrix) #create scatter plot plot(x, y) #add circle at specific (x, y) coordinates with specific radius draw.circle(x=3, y=8, radius=.5)Method 2: Draw Circle Using ggplot2 library(ggplot2) library(ggforce) #create scatter plot with circle at specific location with specific radius ggplot(data = df, aes(x, y)) + geom_point() + geom_circle(aes(x0=3, y0=8, r=1), inherit.aes=FALSE) + coord_fixed()The following examples shows how to use each method in practice. Example 1: Draw Circle Using Base RTo draw a circle on a plot in base R, you need to first install and load the plotrix package: install.packages('plotrix') library(plotrix)Next, we can use the draw.circle() function from the plotrix package to add a circle to a scatter plot in base R: #create data frame df |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |